﻿using System.Web;
using AutoMapper;
using YuYuKiCms.Bl;
using YuYuKiCms.Dal.Model;
using YuYuKiCms.Framework.Extention;
using YuYuKiCms.Model;

[assembly: PreApplicationStartMethod(typeof (AutoMapperConfiguration), "RegisterAutoMapperConfig")]

namespace YuYuKiCms.Bl
{
    public static class AutoMapperConfiguration
    {
        #region Method

        public static void RegisterAutoMapperConfig()
        {
            PageMenu();
            Account();
            Theme();
            Mapper.AssertConfigurationIsValid();
        }

        #endregion

        #region Method private

        private static void Theme()
        {
            Mapper.CreateMap<Theme, ThemeVm>();
            Mapper.CreateMap<ThemeVm, Theme>();
        }

        private static void Account()
        {
            Mapper.CreateMap<LoginVm, UserAccount>()
                .IgnoreAllNonExisting()
                .ForMember(f => f.Email, o => o.MapFrom(p => p.Email))
                .ForMember(f => f.Password, o => o.MapFrom(p => p.Password));

            Mapper.CreateMap<RegistrationVm, UserAccount>()
                .IgnoreAllNonExisting();
        }

        private static void PageMenu()
        {
            Mapper.CreateMap<PageVm, PageMenu>();
            Mapper.CreateMap<PageMenu, PageVm>()
                .ForMember(f => f.Order, o => o.Ignore());
        }

        #endregion
    }
}